<template>
	<view class="sign-in-page">
		<!-- 顶部关闭按钮 -->
		<view class="close-btn" @tap="goBack">×</view>
		
		<!-- 签到信息 -->
		<view class="sign-info">
			<text class="title">累计签到</text>
			<view class="days">
				<text class="number">1</text>
				<text class="unit">天</text>
			</view>
			<text class="desc">超过1%的好友</text>
		</view>
		
		<!-- 日历卡片 -->
		<view class="calendar-card">
			<!-- 星期表头 -->
			<view class="week-header">
				<text v-for="day in ['一','二','三','四','五','六','日']" :key="day">{{ day }}</text>
			</view>
			
			<!-- 日期网格 -->
			<view class="days-grid">
				<!-- 前面的空白日期 -->
				<view class="day-item empty" v-for="i in firstDayOffset" :key="'empty-'+i"></view>
				
				<!-- 实际日期 -->
				<view 
					class="day-item" 
					v-for="day in totalDays" 
					:key="day"
					:class="{
						'signed': isSignedDay(day),
						'today': isToday(day),
						'future': isFutureDay(day)
					}"
				>
					{{ day }}
				</view>
			</view>
			
			<!-- 底部松鼠图片 -->
			<image class="squirrel" src="/static/squirrel.png" mode="aspectFit"></image>
			
			<!-- 月份显示 -->
			<text class="month">{{currentMonth}}月</text>
		</view>
	</view>
</template>

<script setup>
import { ref, onMounted } from 'vue'

// 获取当前日期信息
const currentDate = new Date()
const currentDay = currentDate.getDate()
const currentMonth = currentDate.getMonth() + 1

// 计算当月第一天是星期几（0-6）
const firstDayOffset = new Date(currentDate.getFullYear(), currentDate.getMonth(), 1).getDay()

// 获取当月总天数
const totalDays = new Date(currentDate.getFullYear(), currentDate.getMonth() + 1, 0).getDate()

// 判断日期状态
const isSignedDay = (day) => {
	return day < currentDay
}

const isToday = (day) => {
	return day === currentDay
}

const isFutureDay = (day) => {
	return day > currentDay
}

// 返回上一页
const goBack = () => {
	uni.navigateBack()
}
</script>

<style lang="scss">
.sign-in-page {
	min-height: 100vh;
	background-color: #E8F6F6;
	padding: 40rpx;
	position: relative;
}

.close-btn {
	position: absolute;
	top: 40rpx;
	right: 40rpx;
	width: 60rpx;
	height: 60rpx;
	background: rgba(0, 0, 0, 0.1);
	border-radius: 50%;
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 40rpx;
	color: #666;
}

.sign-info {
	text-align: center;
	margin-top: 120rpx;
	margin-bottom: 60rpx;
	
	.title {
		font-size: 32rpx;
		color: #666;
		margin-bottom: 20rpx;
	}
	
	.days {
		margin-bottom: 16rpx;
		
		.number {
			font-size: 60rpx;
			font-weight: bold;
			color: #333;
		}
		
		.unit {
			font-size: 32rpx;
			color: #333;
			margin-left: 8rpx;
		}
	}
	
	.desc {
		font-size: 28rpx;
		color: #666;
	}
}

.calendar-card {
	background: #FFFFFF;
	border-radius: 20rpx;
	padding: 40rpx;
	position: relative;
	
	.week-header {
		display: grid;
		grid-template-columns: repeat(7, 1fr);
		text-align: center;
		margin-bottom: 30rpx;
		
		text {
			font-size: 28rpx;
			color: #666;
		}
	}
	
	.days-grid {
		display: grid;
		grid-template-columns: repeat(7, 1fr);
		gap: 16rpx;
		
		.day-item {
			height: 70rpx;
			display: flex;
			align-items: center;
			justify-content: center;
			font-size: 28rpx;
			color: #333;
			border-radius: 50%;
			
			&.empty {
				visibility: hidden;
			}
			
			&.signed {
				background: #E8F6F6;
				color: #5CD3D3;
			}
			
			&.today {
				background: #5CD3D3;
				color: #FFFFFF;
			}
			
			&.future {
				color: #999;
			}
		}
	}
	
	.squirrel {
		position: absolute;
		right: 100rpx;
		bottom: 30rpx;
		width: 240rpx;
		height: 240rpx;
		transform: rotate(-15deg);
		opacity: 0.9;
		transform: translate(-380rpx, 230rpx);
	}
	
	.month {
		position: absolute;
		right: 40rpx;
		bottom: 40rpx;
		font-size: 32rpx;
		color: #333;
		z-index: 1;
	}
}
</style>
